package com.qk.ezbuy.controller;

import com.github.pagehelper.PageInfo;
import com.qk.ezbuy.pojo.Product;
import com.qk.ezbuy.pojo.User;
import com.qk.ezbuy.service.ProductService;
import com.qk.ezbuy.dao.ProductCategoryMapper;
import com.qk.ezbuy.pojo.Product;
import com.qk.ezbuy.pojo.ProductCategory;
import com.qk.ezbuy.service.ProductCategoryService;
import com.qk.ezbuy.service.ProductService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/Product")
public class ProductController {
    @Autowired
    private ProductService productService;

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("ProductAll")
    public PageInfo<Product> selectByPage(@RequestParam int pageNum, @RequestParam int pageSize){
        PageInfo<Product> pageInfo=null;
        pageInfo=productService.selectPage(pageNum,pageSize);
        return pageInfo;
    }

    /**
     * 事务删除
     */
    @RequestMapping("ProductDel")
    public Map ProductDel(Product product) {
        Map<String, Object> map = new HashMap<>();
        product.setIsdelete(1);
        int count = productService.updateByPrimaryKeySelective(product);
        if (count > 0) {
            map.put("msg", 1);
        } else {
            map.put("msg", 1);
        }
        return map;
    }
    @Autowired
    private ProductCategoryService productCategoryService;
    @RequestMapping("/selectAll")
    public Map<Object,Object> selectByAll(){
        Map<Object,Object> map = new HashMap<Object,Object>();
        List<ProductCategory> list1 = productCategoryService.selectAll();
        List<Product> list2 = productService.selectAll();
        map.put("listcate",list1);
        map.put("listthing",list2);
        return map;
    }

    @RequestMapping("/selectById")
    public Product selectById(Integer id){
        return productService.selectById(id);
    }

    @RequestMapping("/selectByParentId")
    public PageInfo<Product> selectByLevel(@RequestParam Map<String,Object > map){
        return productService.selectByParentId(map);
    }
}
